
#include "StdAfx.h"
#include "StateNode.h"

StateNode::StateNode( char* name ){
	name_ = name;

	probs_.clear();
	nexts_.clear();
}

StateNode::~StateNode(){
}

char* StateNode::get_name(){
	return (char*)name_.c_str();
}

int StateNode::set_next( int prob, StateNode* node ){
	if(! node )
		return DEFAULT_FAIL;

	if( probs_.size() != nexts_.size() )
		return DEFAULT_FAIL;

	probs_.push_back( prob );
	nexts_.push_back( node );
	
	return DEFAULT_SUCCESS;
}

StateNode* StateNode::process(){
	int size = probs_.size();
	for( int i = 0 ; i < size ; i++ ){
		if( ( rand() % 100 ) < probs_[ i ] ) 
			return nexts_[ i ];
	}
	
	return 0;
}
